<template>
   <div class="page-box">
      <div class="page-title">
         {{ "采购订单审核" }}
      </div>

      <div class="page-search">
         <div
            class="search-box"
            :style="{ height: IsHeight }"
         >
            <el-input
               v-model="pageData.keyword"
               placeholder="采购单号/供应商/负责人"
               style="width: 200px; margin-right: 10px"
               suffix-icon="search"
            />
         </div>
         <div class="search-btn">
            <div
               class="btn_item"
               @click="handleClickHeight"
            >
               <img
                  class="btn_img"
                  src="@/assets/sx.png"
                  alt=""
               />
               <span> 高级筛选 </span>
            </div>
         </div>
      </div>
   </div>

   <div class="table-box">
      <el-table
         :data="tabeData"
         style="width: 100%"
         v-loading="loading"
         border
      >
         <el-table-column
            align="center"
            prop="order_no"
            label="采购单号"
            width="220"
         />
         <el-table-column
            align="center"
            prop="total_amount"
            label="采购金额(元)"
            width="240"
         />
         <el-table-column
            align="center"
            prop="purchase_date"
            label="采购日期"
            width="240"
         >
         </el-table-column>

         <el-table-column
            align="center"
            prop="manager_name"
            label="采购负责人"
            width="140"
         />

         <el-table-column
            align="center"
            prop="manager_phone"
            label="负责人电话"
            width="140"
         />
         <el-table-column
            align="center"
            prop="note"
            label="备注"
            width="140"
         >
            <template #default="scope">
               <p>{{ scope.row.note ? scope.row.note : "--" }}</p>
            </template>
         </el-table-column>
         <el-table-column
            align="center"
            prop="creator_name"
            label="创建人"
            width="140"
         />
         <el-table-column
            align="center"
            prop="created_at"
            label="创建时间"
            width="140"
         />
         <el-table-column
            fixed="right"
            label="操作"
            min-width="90"
            prop="id"
            align="center"
         >
            <template #default="scope">
               <div class="btn-box">
                  <el-button
                     plain
                     size="small"
                     type="primary"
                     @click="handleAudit(scope.row.id)"
                  >
                     审核
                  </el-button>
               </div>
            </template>
         </el-table-column>
      </el-table>
   </div>

   <!-- 分页 -->
   <Pagination
      class="pagination"
      @pageSize="pageSize"
      @getPage="getPage"
      :page="pageData.page"
      :page-size="pageData.pageSize"
      :total="total"
   />

   <rurchaseOrderReview
      ref="dialogRef"
      :order-list="tabeData"
      @refreshList="getAlltabeData"
   />
</template>

<script setup lang="ts">
   import { ref, onMounted, watch } from "vue";
   import { useRouter } from "vue-router";
   import { usePlatformManagementStore } from "@/stores";
   import Pagination from "@/components/Pagination.vue";
   import { ProcurementDetail } from "./procurementType";
   import rurchaseOrderReview from "./components/rurchaseOrderReview.vue";
   const platformManagementStore = usePlatformManagementStore();
   const router = useRouter();
   import api from "@/api/index.js";

   let IsHeight = ref<number | string>(0);
   const dialogRef = ref<any>(null);
   const pageData = ref({
      pageSize: 10,
      page: 1,
      keyword: "",
   });
   const total = ref(0);
   const tabeData = ref<ProcurementDetail[]>([]);
   // 侦听动态分页
   watch(
      () => {
         return pageData.value;
      },
      () => {
         getAlltabeData();
      },
      { deep: true }
   );

   let nub = ref<number>(0);
   const handleClickHeight = () => {
      nub.value++;
      if (nub.value % 2 == 1) {
         IsHeight.value = "40px";
      } else {
         IsHeight.value = "0px";
      }
   };

   const pageSize = (e: number) => {
      pageData.value.pageSize = e;
   };
   const getPage = (e: number) => {
      pageData.value.page = e;
   };
   // 审核
   const handleAudit = (id: number) => {
      dialogRef.value.openLoading(id);
   };
   // 获取采购订单审核列表
   const getAlltabeData = async () => {
      loading.value = true;
      try {
         const res = await api.procurement.purchaseOrderAuditList({
            ...pageData.value,
         });
         if (res.code == 200) {
            tabeData.value = res.data.data;
            total.value = res.data.pager.page_count;
         }
      } catch (error) {
         console.error("获取采购订单审核列表失败", error);
      } finally {
         loading.value = false;
      }
   };

   const loading = ref(false);
   onMounted(() => {
      getAlltabeData();
   });
</script>

<style lang="scss" scoped>
   .btn-box {
      display: flex;
      align-items: center;
      justify-content: center;
   }

   // 输入框样式
   ::v-deep .el-input__wrapper {
      background-color: rgba(250, 252, 251, 1);
   }

   //表格样式

   ::v-deep .el-table {
      --el-table-header-bg-color: rgba(235, 236, 240, 1);
   }

   ::v-deep .el-table thead {
      color: #444;
   }

   //分页样式
   .pagination {
      width: calc(100% - 250px);
      position: fixed;
      bottom: 20px;
      right: 20px;
      padding-top: 10px;
      border-top: 1px solid #98989848;
   }

   ::v-deep .el-pagination.is-background .el-pager li.is-active {
      background-color: #000 !important;
   }
   :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
      background-color: #6860ff;
      border-color: #6860ff;
   }
   :deep(.el-checkbox__inner:hover) {
      border-color: #626aef !important;
   }
   :deep(.el-checkbox__input.is-indeterminate .el-checkbox__inner) {
      background-color: #6860ff;
   }
   :deep(.el-checkbox__input.is-indeterminate .el-checkbox__inner) {
      border-color: #6860ff;
   }
   :deep(.el-button:hover) {
      background-color: #e2e4fd;
      color: #6860ff;
   }
   :deep(.el-input__wrapper:hover) {
      box-shadow: inset 0 0 0 1px #6860ff;
   }
</style>
